/* util */
import { isOpenData } from '@src/util/platform'
/* model */
import Field from '@model/entity/Field'
import Auth from '@model/entity/Auth'
import RootWindowInitData from '@model/interface/initData/RootWindowInitData'
/* service */
import AuthService from '@service/AuthService'
/* util */
import { getRootWindowInitData } from '@src/util/window'
/* vue */
import { defineComponent, ComputedOptions } from 'vue'



type AuthMixinProps = {
  
}

type AuthMixinData = {
  isOpenData: boolean;
  rootWindowInitData: RootWindowInitData;
}

export type AuthMixinComputedOptions = {
  globalLoginUserAuth: () => Auth;
  globalIsHaveCallCenterViewDetailAuth: () => boolean;
  globalIsHaveImViewDetailAuth: () => boolean;
  globalIsHaveEventViewDetailAuth: () => boolean;
  globalIsHaveCustomerViewDetailAuth: () => boolean;
  globalIsHaveProductViewDetailAuth: () => boolean;
  globalIsHaveProductCatalogViewDetailAuth: () => boolean;
  globalIsHaveTaskViewDetailAuth: () => boolean;
  globalIsHaveCallCenterExportAuth: () => boolean;
  globalIsHaveCallCenterEditAuth: () => boolean;
  globalIsHaveAccountViewAuth: () => boolean;
}

type AuthMixinMethodsOptions = {
  uuid: () => string;
  getPerformanceShowTooltip: (field: Field) => boolean;
  getProductTypeListShowTooltip: (field: Field) => boolean;
  getSparePartPersonalUserNameShowTooltip: (field: Field) => boolean;
  getCommonListShowTooltip: (field: Field) => boolean;
  getEventListShowTooltip: (field: Field) => boolean;
  getProductListShowTooltip: (field: Field) => boolean;
  globalFormSubmissionDataProcessingHandler: (fields: Field[], formData: Record<string, any>) => Record<string, any>;
}

export type AuthMixinVM =  AuthMixinComputedOptions & AuthMixinMethodsOptions

export default defineComponent<AuthMixinProps, AuthMixinData, AuthMixinData, AuthMixinComputedOptions, AuthMixinMethodsOptions>({
  data() {
    return {
      isOpenData,
      rootWindowInitData: getRootWindowInitData(),
    }
  },
  computed: {
    /** 
     * @description 全局登录用户权限
    */
    globalLoginUserAuth(): Auth | Record<string, number> {
      return (this.rootWindowInitData?.user?.auth || {}) as Auth
    },
    globalIsHaveCallCenterViewDetailAuth() {
      return AuthService.isHaveCallCenterViewDetailAuth(this.globalLoginUserAuth)
    },
    globalIsHaveImViewDetailAuth() {
      return AuthService.isHaveImViewDetailAuth(this.globalLoginUserAuth)
    },
    globalIsHaveEventViewDetailAuth() {
      return AuthService.isHaveEventViewDetailAuth(this.globalLoginUserAuth)
    },
    globalIsHaveCustomerViewDetailAuth() {
      return AuthService.isHaveCustomerViewDetailAuth(this.globalLoginUserAuth)
    },
    globalIsHaveProductViewDetailAuth() {
      return AuthService.isHaveProductViewDetailAuth(this.globalLoginUserAuth)
    },
    globalIsHaveProductCatalogViewDetailAuth() {
      return AuthService.isHaveProductCatalogViewDetailAuth(this.globalLoginUserAuth)
    },
    globalIsHaveTaskViewDetailAuth() {
      return AuthService.isHaveTaskViewDetailAuth(this.globalLoginUserAuth)
    },
    globalIsHaveCallCenterExportAuth() {
      return AuthService.isHaveCallCenterExportAuth(this.globalLoginUserAuth)
    },
    globalIsHaveCallCenterEditAuth() {
      return AuthService.isHaveCallCenterEditAuth(this.globalLoginUserAuth)
    },
    globalIsHaveAccountViewAuth() {
      return AuthService.isHaveAccountViewDetailAuth(this.globalLoginUserAuth)
    },
  },
  mounted() {
    // console.log('AuthMixin mounted')
    // console.log(this.globalLoginUserAuth)
  }
})

